<include file="public@header"/>
<style type="text/css">  
input{  
    width:150px;  
    padding:1px;  
}  
#popup{  
    position:absolute;  
    width:500px;  
    color:#004a7e; 
    background-color:#C0C0C0;   
    /*left:120px;  */
    top:33px;  
}  
#spopup{  
    position:absolute;  
    width:500px;  
    color:#004a7e; 
    background-color:#C0C0C0;   
    /*left:120px;  */
    top:33px;  
}  
.show{  
    border:1px solid #909090;  
}  
ul{  
    list-style-type:none;  
    color:#004a7e;  
}  
._hover{  
    color:#ffffff;  
    background-color:#004a7e;  
}  
 ul{margin:0;padding:0}
</style>  
<script type="text/html" id="files-item-tpl">
    <li id="saved-file{id}">
        <input id="file-{id}" type="hidden" name="file_urls[]" value="{filepath}">
        <input class="form-control" id="file-{id}-name" type="text" name="file_names[]" value="{name}"
               style="width: 200px;" title="文件名称">
        <a id="file-{id}-preview" href="{preview_url}" target="_blank">下载</a>
      <!--   <a href="javascript:uploadOneFile('图片上传','#file-{id}');">替换</a> -->
        <a href="javascript:(function(){$('#saved-file{id}').remove();})();">移除</a>
    </li>
</script>
<script type="text/html" id="photos-item-tpl">
    <li id="saved-image{id}">
        <input id="photo-{id}" type="hidden" name="photo_urls[]" value="{filepath}">
        <input class="form-control" id="photo-{id}-name" type="text" name="photo_names[]" value="{name}"
               style="width: 200px;" title="图片名称">
        <img id="photo-{id}-preview" src="{url}" style="height:36px;width: 36px;"
             onclick="imagePreviewDialog(this.src);">
       <!--  <a href="javascript:uploadOneImage('图片上传','#photo-{id}');">替换</a> -->
        <a href="javascript:(function(){$('#saved-image{id}').remove();})();">移除</a>
    </li>
</script>
</head>
<body>

	<div class="wrap">
		<ul class="nav nav-tabs">

			<li><a href="{:url('Order/index')}">运营中心</a></li>
			<li class="active"><a href="{:url('Order/addOrder')}">添加</a></li>
			<!-- 	<li class="active><a href="{:url('station/index')}">园区添加</a></li> -->
			<!-- <li ><a href="javascript:;">编辑分类</a></li> -->
		</ul>

		<form method="post" class="form-horizontal  margin-top-20" action="addOrder">
		    <input type="hidden" name="incubator_id" value="">
		    <input type="hidden" name="space_name" value="">
		    <input type="hidden" name="customer_name" value="">
		    <input type="hidden" name="customer_id" value="">
		    <input type="hidden" name="salesman" value="">
		    <input type="hidden" name="room_type" value="">
		    <input type="hidden" name="room_id" value="">
			<div class="form-group">
				<label for="input-name" class="col-sm-2 control-label">租赁类型<span class="form-required">*</span></label>
				<div class="col-md-6 col-sm-10">
					<select class="form-control  space_type" name="space_type" id="parent_id"  required="true">
						<option value="">==请选择==</option>
						<option value="1">空间</option>
						<option value="2">场地</option>
						
					</select>
				</div>
			</div>

			<div class="form-group">
				<label for="input-name" class="col-sm-2 control-label">空间名称</label>
				<div class="col-md-6 col-sm-10">
					<select class="form-control space_name" name="space_id" id="parent_id" required="true">
						<option value="">==请选择==</option>
					
						
					</select>
				</div>
			</div>
			<div class="form-group">
				<label for="input-name" class="col-sm-2 control-label">客户名<span class="form-required">*</span></label>
				<div class="col-md-6 col-sm-10">
				<input class="form-control" type="text" name="names" id="names" value="" onkeyup="findNames()" required="true" autocomplete="off">
					<!-- <select class="form-control  " name="customer_id" id="parent_id"  >
						<option value="">==请选择==</option>
						<volist name="customers" id="vo">
						  <option value="{$vo.id}">{$vo.customer_name}</option>
						</volist>
					
						
					</select> -->
					<div  id="popup" style="z-index:2;float:left">  
					<ul id="ul_name"></ul>  
				</div>  
				</div>
				
			</div>

			<!-- <div class="form-group">
				<label for="input-name" class="col-sm-2 control-label">状态</label>
				<div class="col-md-6 col-sm-10">
					<select class="form-control" name="status" id="parent_id" required="true">
						<option value="">==请选择==</option>
						<option value="1">可用</option>
						<option value="0">禁用</option>
						
					</select>
				</div>
			</div> -->
		<!-- 	<div class="form-group">
				<label for="input-name" class="col-sm-2 control-label">企业名<span class="form-required"></span></label>
				<div class="col-md-6 col-sm-10">
					<input class="form-control" type="text" name="commpany_name" value="" >
				</div>
			</div> -->
			<div class="form-group">
				<label for="input-name" class="col-sm-2 control-label">电话<span class="form-required">*</span></label>
				<div class="col-md-6 col-sm-10">
					<input class="form-control" type="text" name="mobile" value="" required="true">
				</div>
			</div>
		<!-- 	<div class="form-group">
				<label for="input-name" class="col-sm-2 control-label">图片<span class="form-required">*</span></label>
				<div class="col-md-6 col-sm-10">
					<input class="form-control" type="text" name="pic" value="" >
				</div>
			</div> -->
			<!-- <div class="form-group">
				<label for="input-name" class="col-sm-2 control-label">图<span class="form-required">*</span></label>
				<div class="col-md-6 col-sm-10">
					<input class="form-control" type="text" name="pic_url" value="" required="true">
				</div>
			</div> -->
			<!-- <div class="form-group">
				<label for="input-name" class="col-sm-2 control-label">合同附件<span class="form-required">*</span></label>
				<div class="col-md-6 col-sm-10">
				 <ul id="photos" class="pic-list list-unstyled form-inline"></ul>
                            <a href="javascript:uploadMultiImage('图片上传','#photos','photos-item-tpl');"
                               class="btn btn-default btn-sm">选择图片</a>
				</div>
			</div> -->
			<div class="form-group">
				<label for="input-name" class="col-sm-2 control-label">图片</label>
				<div class="col-md-6 col-sm-10">
					<imagetpl name="pic" id="img" value=""/>
				</div>
			</div>
		<!-- 	<div class="form-group">
				<label for="input-name" class="col-sm-2 control-label">单价<span class="form-required">*</span></label>
				<div class="col-md-6 col-sm-10">
					<input class="form-control" type="text" name="price" value="" >
				</div>
			</div> -->
			<div class="form-group">
				<label for="input-name" class="col-sm-2 control-label">租赁数<span class="form-required">*</span></label>
				<div class="col-md-2 col-sm-10">
					<input class="form-control" type="text" name="amount" value="1" >
				</div><label for="input-name" class="control-label unit">个</label>
			</div>
		<!-- 	<div class="form-group">
				<label for="input-name" class="col-sm-2 control-label">单价<span class="form-required">*</span></label>
				<div class="col-md-6 col-sm-10">
					<input class="form-control" type="text" name="price" value="" >
				</div>
			</div> -->
			<div class="form-group">
				<label for="input-name" class="col-sm-2 control-label">服务费<span class="form-required">*</span></label>
				<div class="col-md-6 col-sm-10">
					<input class="form-control" type="text" name="service_price" value="" >
				</div>
			</div>
			<div class="form-group">
				<label for="input-name" class="col-sm-2 control-label">押金<span class="form-required">*</span></label>
				<div class="col-md-6 col-sm-10">
					<input class="form-control" type="text" name="deposit_price" value="" >
				</div>
			</div>
			<div class="form-group">
				<label for="input-name" class="col-sm-2 control-label">是否开收据</label>
				<div class="col-md-6 col-sm-10">
					<select class="form-control" name="is_receipt" id="parent_id">
						<option value="">==请选择==</option>
						<option value="1">是</option>
						<option value="0">否</option>
						
					</select>
				</div>
			</div>
		<!-- 	<div class="form-group">
				<label for="input-name" class="col-sm-2 control-label">租金总额<span class="form-required">*</span></label>
				<div class="col-md-6 col-sm-10">
					<input class="form-control" type="text" name="sum_price" value="" >
				</div>
			</div> -->
			<div class="form-group">
				<label for="input-name" class="col-sm-2 control-label">支付方式<span class="form-required">*</span></label>
				<div class="col-md-6 col-sm-10">
					<select class="form-control" name="payway_id" id="parent_id" required="true">
						<option value="">==请选择==</option>
						<option value="1">年</option>
						<option value="2">半年</option>
						<option value="3">季度</option>
						<option value="4">月</option>
						<option value="5">次</option>
						
					</select>
				</div>
			</div>


		<!-- 	<div class="form-group">
				<label for="input-name" class="col-sm-2 control-label">空间名称<span class="form-required">*</span></label>
				<div class="col-md-6 col-sm-10">
					<input class="form-control" type="text" name="space_name" value="" required="true">
				</div>
			</div> -->

			<div class="form-group">
				<label for="input-name" class="col-sm-2 control-label">合同时间<span class="form-required">*</span></label>
				<div class="col-md-6 col-sm-10 space">
				
					<input type="text" class="form-control js-bootstrap-date " name="stime"
					value="{$start_time|default=''}"
					 required="true">-
					<input type="text" class="form-control js-bootstrap-date" name="etime"
					value="{$end_time|default=''}"
					  required="true">
				</div>
				<div class="col-md-6 col-sm-10 site" style="display: none">
				
					<input type="text" class="form-control js-bootstrap-datetime " name="stime"
					value="{$start_time|default=''}"
					 required="true">-
					<input type="text" class="form-control js-bootstrap-datetime" name="etime"
					value="{$end_time|default=''}"
					  required="true">
				</div>
			</div>

		<!-- 	<div class="form-group">
				<label for="input-name" class="col-sm-2 control-label">业务员<span class="form-required">*</span></label>
				<div class="col-md-6 col-sm-10">
					<input class="form-control" type="text" name="salesman" value="" >
				</div>
			</div> -->
			<div class="form-group">
				<label for="input-name" class="col-sm-2 control-label">业务员<span class="form-required"></span></label>
				<div class="col-md-6 col-sm-10">
					<!-- <input class="form-control" type="text" name="other_link" value="" > -->
					<!-- <select class="form-control" name="salesman" id="parent_id">
						<option value="">==选择业务员==</option>\
						<volist name="salesman" id="vo">
								<option value="{$vo.id}">{$vo.user_login}</option>
						</volist>
					
					</select> -->
					<input class="form-control" type="text" name="snames" id="snames" value="" onkeyup="sfindNames()"  autocomplete="off">
					<!-- <select class="form-control  " name="customer_id" id="parent_id"  >
						<option value="">==请选择==</option>
						<volist name="customers" id="vo">
						  <option value="{$vo.id}">{$vo.customer_name}</option>
						</volist>
					
				
				</div>		
					</select> -->
					<div  id="spopup" style="z-index:2;float:left">  
						<ul id="sul_name"></ul>  
				   </div>
					</div>	
				
			</div>
			<!-- <div class="form-group">
				<label for="input-name" class="col-sm-2 control-label">合同附件<span class="form-required">*</span></label>
				<div class="col-md-6 col-sm-10">
					<input class="form-control" type="file" name="file" value="" >
				</div>
			</div> -->
			<div class="form-group">
				<label for="input-name" class="col-sm-2 control-label">合同附件<span class="form-required">*</span></label>
				<div class="col-md-6 col-sm-10">
				<ul id="files" class="pic-list list-unstyled form-inline">
				</ul>
				<a href="javascript:uploadMultiFile('附件上传','#files','files-item-tpl');"
				class="btn btn-sm btn-default">选择文件</a>
				</div>
			</div>


			

		</div>
			
<!-- 				<label for="input-remark" class="col-sm-2 control-label">备注</label> -->
			<!-- 	<div class="col-md-6 col-sm-10">
					<label class="radio-inline js-icheck"><input type="radio" name="status" value="1" checked>显示</label>
					<label class="radio-inline js-icheck"><input type="radio" name="status" value="0" <if condition="1">checked</if>>隐藏</label>
				</div> -->
			<!-- </div>  -->
			<div class="form-group">
				<div class="col-sm-offset-2 col-sm-10">
					<!-- <input type="hidden" name="id" value="1"> -->
					<button type="submit" class="btn btn-primary js-ajax-submit">{:lang('SAVE')}</button>
					<a class="btn btn-default" href="{:url('index',['type_id'=>1])}">{:lang('BACK')}</a>
				</div>
			</div>
		</form>
	</div>
	<script src="__STATIC__/js/admin.js"></script>
	<script type="text/javascript">
		var b=$(".space_name option:first").text();  
		$(".space_name").html("<option value=''>"+b+"</option>");  
        var type=$(".space_type").val();
        if(type==2){
        	$(".site").css('display','');
        	$(".space").css('display','none');
        }else{
        	$(".site").css('display','none');
        	$(".space").css('display','');
        }
        var option;
        $.post("{:url('Order/get_space')}",{type:type,edit:'',space_id:''},function(data,status){
        		$.each(data,function(i,j){

        			if(type==1){
        				option+='<option class='+j.incubator_id+' value='+j.id+'>'+j.station_name+'</option>';	
        			}else{
        				option+='<option class='+j.incubator_id+' value='+j.id+'>'+j.site_name+'</option>';
        			}
        		
        		})
        		$(".space_name").append(option);
        })
		role=<?php echo $role; ?>;
		namess="{$namess}";

		if(role==3){
			$('#snames').val(namess);
			$('#snames').attr('readonly','readonly');
			snames=$("#snames").val();
			//alert(snames);
			//$("input[name=customer_name]").val(customer_name);
			//alert(customer_name);
			// a='<?php echo $a='+customer_name+ '?>';
			// alert
			$.post("{:url('Order/getSalesId')}",{snames:snames},function(data,status){
				$("input[name=salesman]").val(data);



			})
		}
		$("#popup").click(function(){

			names=$("#names").val();
			$("input[name=customer_name]").val(names);
			//alert(names);
			//$("input[name=customer_name]").val(customer_name);
			//alert(customer_name);
			// a='<?php echo $a='+customer_name+ '?>';
			// alert
			$.post("{:url('Order/getCustomerId')}",{customer_name:names},function(data,status){
                     $("input[name=customer_id]").val(data);

			

			 })
			});
			//$("input[name=customer_name]").val(customer_name);

		//alert(22222);
		$("#spopup").click(function(){

			snames=$("#snames").val();
			//alert(snames);
			//$("input[name=customer_name]").val(customer_name);
			//alert(customer_name);
			// a='<?php echo $a='+customer_name+ '?>';
			// alert
			 $.post("{:url('Order/getSalesId')}",{snames:snames},function(data,status){
                      $("input[name=salesman]").val(data);

			

			 })
			//$("input[name=customer_name]").val(customer_name);

		});
	$(".js-ajax-submit").click(function(){
		  var type=$(".space_type").val();
		  if(type==1){
		  	$(".site").remove();
		  }else{
		  	$(".space").remove();
		  }
	})
	$(".space_name").change(function(){
		space_id=$(this).val();	
		 $("input[name=room_id]").val(space_id);	
		// alert(222);


	})
	$(".space_type").change(function(){
		var b=$(".space_name option:first").text();  
		$(".space_name").html("<option value=''>"+b+"</option>");  
        var type=$(".space_type").val();
        $("input[name=room_type]").val(type);
        if(type==2){
        	$(".site").css('display','');
        	$(".space").css('display','none');
        }else{
        	$(".site").css('display','none');
        	$(".space").css('display','');
        }
        var option;
        $.post("{:url('Order/get_space')}",{type:type,edit:'',space_id:''},function(data,status){
        		$.each(data,function(i,j){

        			if(type==1){
        				option+='<option class='+j.incubator_id+' value='+j.id+'>'+j.station_name+'</option>';	
        			}else{
        				option+='<option class='+j.incubator_id+' value='+j.id+'>'+j.site_name+'</option>';
        			}
        		
        		})
        		$(".space_name").append(option);
        })
        //alert(2222);
        if(type==2){
        	$("select[name=payway_id]").html("<option value='5' selected>次</option>");
        	$("select[name=payway_id]").attr("readonly","readonly");
        }else{
        	$("select[name=payway_id]").html("<option value=''>==请选择==</option><option value='1'>年</option><option value='2'>半年</option><option value='3'>季度</option><option value='4'>月</option>");
        }
        
       // alert(option);
	})
	$(".space_name").change(function(){
		name=$(this).find("option:selected").text();
		$("input[name=space_name]").val(name);
	})
	$("select[name=customer_id]").change(function(){
		name=$(this).find("option:selected").text();
		$("input[name=customer_name]").val(name);
	})
	$(".space_name").change(function(){
		// val=$(this).attr('class');
		// alert(val);
		val=$(".space_name option:selected").attr("class");
		$("input[name=incubator_id]").val(val);
		//alert(val);
	})













	var oInput;  
	var oPopDiv;  
	var oNameUl;  

	function initVars(){  
		oInput = $("#names");  
		oPopDiv = $("#popup");  
		oNameUl = $("#ul_name");  
	}  
	function clearNames(){  
		oNameUl.empty();  
		oPopDiv.removeClass("show");  
	}  
	function setNames(the_names){  
		clearNames();  
		oPopDiv.addClass("show");  
		for(var i=0;i<the_names.length;i++)  
			oNameUl.append($("<li>"+the_names[i]+"</li>"));  
		oNameUl.find("li").click(function(){  
			oInput.val($(this).text());  
			clearNames();  
		}).hover(  
		function(){  
			$(this).addClass("_hover");},  
			function(){  
				$(this).removeClass("_hover");}  
				);  
	}  

	$("#names").change(function(){
		//alert(31231);
		findNamess()
	})
	function findNames(){  
		initVars();  
		if(oInput.val().length >0){  
			$.post(  
				"{:url('Order/tip')}",{oData: oInput.val()} ,function(data){  
					// if(data==''){
					// 	alert('该客户不存在，请先添加此客户');
					// 	if(confirm("该客户不存在，请先添加此客户")){
					// 		location.href="{:url('Customer/addCustomers')}";
					// 	}
					// }
					var aResult = new Array();  
					if(data.length>0){  
						aResult = data.split(",");  
						setNames(aResult);  
					}  
					else  
						clearNames();  
				});  
		}  
		else  
			clearNames();  
	}  

	function findNamess(){  
			initVars();  
			if(oInput.val().length >0){  
				$.post(  
					"{:url('Order/tips')}",{oData: oInput.val()} ,function(data){  
						if(data==''){
							//alert('该客户不存在，请先添加此客户');
							if(confirm("该客户不存在，需要添加此客户吗？")){
								location.href="{:url('Customer/addCustomers')}";
							}else{
								$("#names").val('');
							}
						}
						var aResult = new Array();  
						// if(data.length>0){  
						// 	aResult = data.split(",");  
						// 	setNames(aResult);  
						// }  
						// else  
						// 	clearNames();  
					});  
			}  
			else  
				clearNames();  
		}  









	var soInput;  
	var soPopDiv;  
	var soNameUl;  
	
	function sinitVars(){  
		soInput = $("#snames");  
		soPopDiv = $("#spopup");  
		soNameUl = $("#sul_name");  
	}  
	function sclearNames(){  
		soNameUl.empty();  
		soPopDiv.removeClass("show");  
	}  
	function ssetNames(the_names){  
		sclearNames();  
		soPopDiv.addClass("show");  
		for(var i=0;i<the_names.length;i++)  
			soNameUl.append($("<li>"+the_names[i]+"</li>"));  
		soNameUl.find("li").click(function(){  
			soInput.val($(this).text());  
			sclearNames();  
		}).hover(  
		function(){  
			$(this).addClass("_hover");},  
			function(){  
				$(this).removeClass("_hover");}  
				);  
	}  
	$("#snames").change(function(){
		//alert(31231);
		sfindNamess()
	})
	
	function sfindNames(){  
		room_type=$("input[name=room_type]").val();
		room_id=$("input[name=room_id]").val();
		// alert(room_type);
		// alert(room_id);
		//alert(1231);
		sinitVars();  
		if(soInput.val().length >0){  
			$.post(  
				"{:url('Order/salesTip')}",{oData: soInput.val(),room_type:room_type,room_id:room_id} ,function(data){  
					var aResult = new Array(); 
				
					if(data.length>0){  
						aResult = data.split(",");  
						ssetNames(aResult);  
					}  
					else  
						sclearNames();  
				});  
		}  
		else  
			sclearNames();  
	}  
	function sfindNamess(){  
		room_type=$("input[name=room_type]").val();
		room_id=$("input[name=room_id]").val();
		//alert(1231);
		sinitVars();  
		if(soInput.val().length >0){  
			$.post(  
				"{:url('Order/salesTips')}",{oData: soInput.val(),room_type:room_type,room_id:room_id} ,function(data){  
					var aResult = new Array(); 
					if(data==''){
						if(role!=3){
							//alert(soInput.val());
							sales=soInput.val();
							//alert(sales);
							if(confirm("该业务员不存在，需要添加此业务员？")){
								location.href="{:url('User/adds')}?sales="+sales;
							}else{
								$("#snames").val('');	
							}
						}else{

						}
						//alert('该客户不存在，请先添加此客户');
						
					} 
					// if(data.length>0){  
					// 	aResult = data.split(",");  
					// 	ssetNames(aResult);  
					// }  
					// else  
					// 	sclearNames();  
				});  
		}  
		else  
			sclearNames();  
	}  
  
	</script>
</body>
</html>